package com.yubest.springboothello.controller;

import com.yubest.springboothello.interceptors.MdcInterceptor;
import com.yubest.springboothello.service.AsyncService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: hweiyu
 * @Date: 2024/8/1 10:09
 */
@RestController
@Slf4j
public class MdcController {

    @Autowired
    private AsyncService asyncService;

    @GetMapping(value = "/mdc/test")
    public String test() {
        String traceId = MDC.get(MdcInterceptor.TRACE_ID);
        log.info("MDC 测试，traceId: {}", traceId);
        asyncService.exec();
        return "ok";
    }
}
